const questions = [
    { type: "multiple-choice", question: "Question 1: What is 2 + 2?", options: ["3", "4", "5", "6"], answer: "4" },
    { type: "open-ended", question: "Question 2: Who are you?", answer: "ChenYS" },
    // ... Add more questions here
  ];
  
  const questionsContainer = document.getElementById('questions');
  
  questions.forEach((item, index) => {
    const questionDiv = document.createElement('div');
    questionDiv.classList.add('question');
    
    if (item.type === "multiple-choice") {
      let optionsHtml = "";
      item.options.forEach((option, i) => {
        optionsHtml += `<input type="radio" id="option${index}-${i}" name="question${index}" value="${option}">
                        <label for="option${index}-${i}">${option}</label><br>`;
      });
      questionDiv.innerHTML = `<p>${item.question}</p>${optionsHtml}`;
    } else if (item.type === "open-ended") {
      questionDiv.innerHTML = `<p>${item.question}</p>
                               <input type="text" id="answer${index}" placeholder="Your Answer">`;
    }
  
    questionsContainer.appendChild(questionDiv);
  });
  
  document.getElementById('submitBtn').addEventListener('click', () => {
    let score = 0;
    questions.forEach((item, index) => {
      if (item.type === "multiple-choice") {
        const selectedOption = document.querySelector(`input[name="question${index}"]:checked`);
        if (selectedOption && selectedOption.value.toLowerCase() === item.answer.toLowerCase()) {
          score++;
        }
      } else if (item.type === "open-ended") {
        const userAnswer = document.getElementById(`answer${index}`).value.trim();
        if (userAnswer.toLowerCase() === item.answer.toLowerCase()) {
          score++;
        }
      }
    });
    alert(`你的选择题得分是: ${score}/${questions.length}`);
  });
  